package com.xinqi.modules.sys.textbook.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.sys.textbook.domain.CloudTextbookContentEntity;
import com.xinqi.modules.sys.textbook.dto.req.CloudTextbookContentCreateDTO;
import com.xinqi.modules.sys.textbook.dto.req.CloudTextbookContentUpdateDTO;
import com.xinqi.modules.sys.textbook.dto.rsp.CloudTextbookContentResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 云课本课堂内容转换
 *
 * @author: linkai
 * @date: 2023/04/25
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class CloudTextbookContentConvert {
    @Mapping(target = "file", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFile()))")
    public abstract CloudTextbookContentEntity create(CloudTextbookContentCreateDTO s);

    @Mapping(target = "file", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFile()))")
    public abstract CloudTextbookContentEntity update(CloudTextbookContentUpdateDTO s, @MappingTarget CloudTextbookContentEntity t);

    @Mapping(target = "file", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFile()))")
    public abstract CloudTextbookContentEntity update(CloudTextbookContentUpdateDTO s);

    @Mapping(target = "file", expression = "java(com.xinqi.common.base.utils.json.JSON.parse(s.getFile(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    public abstract CloudTextbookContentResultDTO convert(CloudTextbookContentEntity s);
}
